<?php

namespace Mage\ApiBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\Security\Core\SecurityContext;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Acme\EventBundle\Entity\Information;
use Acme\EventBundle\Entity\Inscription;
use Acme\EventBundle\Entity\Feedback;
use Acme\EventBundle\Entity\Aperolocation;
use Acme\EventBundle\Entity\Statisticgroup;
use Acme\EventBundle\Entity\Statisticparameter;
use Acme\EventBundle\Entity\Statisticvalue;
use Acme\AdminBundle\Entity\Document;
use Mage\ApiBundle\Soap\MagConnect;
//use Symfony\Component\Form\Extension\Core\ChoiceList\ChoiceList;
//use Mage\ApiBundle\Form\Type\CatType;
use Doctrine\ORM\EntityRepository;


// these import the "@Route" and "@Template" annotations
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
use Symfony\Component\Validator\Constraints\DateTime;

/**
 * @Route("/auth/security/mage")
 */
class CreateController extends Controller
{
    public function indexAction($name)
    {
        return $this->render('MageApiBundle:Default:index.html.twig', array('name' => $name));
    }
    
    /**
     * @Route("/new", name="api_new")
     * @Template()
     */
    public function newAction(Request $request){

    	$mag = new MagConnect();
    	$mag->getCategories()->getHtmlResponse();
    	
    	//print_r($mag->getCategories()->getHtmlResponse()); exit;
    	
    	$form = $this->createFormBuilder ( $this->getRequest ()->get ( 'form' ) )
    		->add ( 'name', 'text', array ( 'required' => true, 'label' => 'Name' ))
 			->add ( 'description', 'textarea', array ( 'required' => true, 'label' => 'Beschreibung' ))
 			->add ( 'short_description', 'textarea', array ( 'required' => true, 'label' => 'Kurzbeschreibung' ))
 			->add ( 'indicies', 'textarea', array ( 'required' => false, 'label' => 'Technische Beschreibung' ))
 			->add ( 'status', 'choice', array ( 'required' => true, 'choices' => array('1' => 'Aktiviert', '2' => 'Deaktiviert'), 'label' => 'Status' ))
    		->add ( 'visibility', 'choice', array ( 'required' => true, 'choices' => array('1' => 'Einzeln nicht sichtbar', '2' => 'Katalog', '3' => 'Suche', '4' => 'Katalog, Suche'), 'label' => 'Sichtbarkeit' ))
    		->add ( 'price', 'text', array ( 'required' => true, 'label' => 'Marktwert' ))
    		->add ( 'price_week', 'text', array ( 'required' => true, 'label' => 'Preis Wochenende' ))
    		->add ( 'price_weekend', 'text', array ( 'required' => true, 'label' => 'Preis Woche' ))
    		->add ( 'tax_class_id', 'choice', array ( 'required' => true, 'choices' => array('0' => 'keine', '5' => 'MwSt.'), 'label' => 'MwSt.' ))
    		->add ( 'websites', 'hidden', array('data' => '1'))		
    		->add ( 'categories', 'choice', array(
    				'label' => 'Kategorien',
    				'choices'   => array(
    						$mag->getCategories()->getHtmlResponse()
    				),
    				'multiple'  => true,
    				'expanded'	=> true
    		))
    		->add ( 'meta_title', 'text', array ( 'required' => false, 'label' => 'Meta Titel' ))
    		->add ( 'meta_keyword', 'text', array ( 'required' => false, 'label' => 'Meta Schlüsselwörter' ))
    		->add ( 'meta_description', 'textarea', array ( 'required' => true, 'label' => 'Meta Beschreibung' ))
    		->add ( 'save', 'submit', array ( 'label' => 'Erfassen und SELV Member informieren'))
    	->getForm ();
    	 
    	$form->handleRequest ( $this->getRequest () );
    	
    	if ($form->isValid ()) {
    		
    		print_r($request->request->get ( 'form' )); exit;
    		//echo "OK"; exit;	 
    	}
    	
    	// password 
    	// U&bFS{V`+wE7XZ=
    	
    	//print_r($result);
    	
    	//echo $this->getNavigation($result['children']); exit;
    	
    	$pagedata = $this->get ( 'common_pagedata' );
    	$arr_data = $pagedata->getCommonSecurity ();
    	 
    	return array (
    			'user' => $arr_data ["usr"],
    			'personimagest' => $arr_data ["personimagest"],
    			'personimages' => $arr_data ["personimages"],
    			'persons' => $arr_data ["persons"],
    			'usersinformation' => $arr_data ["usersinformation"],
    			'inscriptions' => $arr_data ["inscriptions"],
    			'information_datum' => $arr_data ["information_datum"],
    			'form' => $form->createView (),
    			//'checkbox' => $this->getNavigation($result['children'])
    			// 'otheruser' => $arr_data["otheruser"]
    	);
    }

    
}
